/**
 * 
 */
package com.suma.android.util;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author Administrator
 * 
 */
public class JSONUtil {

	private static final String URL = "url";
	private static final String LIVE = "live";
	private static final String PUSH_URL = "pushurl";
	private static final String PAD = "pad";
	private static final String PC = "pc";
	private static final String MOBILE = "mobile";
	private static final String STB = "stb";

	public static VideoConfig parse(String str) {
		VideoConfig config = null;
		try {
			JSONObject json = new JSONObject(str);
			config = new VideoConfig();
			if (json.has(URL)) {
				config.setUrl(json.getString(URL));
			}
			if (json.has(LIVE)) {
				config.setLive(json.getBoolean(LIVE));
			}
			if (json.has(PUSH_URL)) {
				JSONObject pushjson = json.getJSONObject(PUSH_URL);
				VideoConfig.PushUrl pushurl = config.new PushUrl();
				config.setPushurl(pushurl);
				if (pushjson.has(PAD)) {
					pushurl.setPad(pushjson.getString(PAD));
				}
				if (pushjson.has(PC)) {
					pushurl.setPc(pushjson.getString(PC));
				}
				if (pushjson.has(MOBILE)) {
					pushurl.setMobile(pushjson.getString(MOBILE));
				}
				if (pushjson.has(STB)) {
					pushurl.setStb(pushjson.getString(STB));
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return config;
	}

}
